/**
 * 
 */
package cn.edu.bjtu.textprocess.core;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

import org.deeplearning4j.util.ModelSerializer;
import org.textplantform.common.Constant;
import org.textplantform.common.core.Deep4jModelType;
import org.textplantform.common.provider.NetworkModelService;

/**
 * @author alex
 *
 */

class LocalFileModelReader implements NetworkModelService{
	Properties p = new Properties();
	byte [] modelByte = null;
	/**
	 */
	public LocalFileModelReader() throws Exception{
		//默认4M
		ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
		// TODO Auto-generated constructor stub
		p.load(this.getClass().getClassLoader().getResourceAsStream("meta/"+Constant.Values.ConfigFileName));
		InputStream input = LocalFileModelReader.class.getClassLoader().getResourceAsStream("meta/"+Constant.Values.ModelFileName);
		ModelSerializer.restoreComputationGraph(input);
		modelByte = baos.toByteArray();
	}
	/* (non-Javadoc)
	 * @see org.textplantform.common.provider.NetworkModelService#lastModifiedTime()
	 */
	@Override
	public Date lastModifiedTime() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.textplantform.common.provider.NetworkModelService#getType()
	 */
	@Override
	public Deep4jModelType getType() {
		// TODO Auto-generated method stub
		return p.getProperty("CNN_TYPE").equals("CG")?Deep4jModelType.ComputationGraph:Deep4jModelType.MultiLayerNetwork;
	}

	/* (non-Javadoc)
	 * @see org.textplantform.common.provider.NetworkModelService#getSentenceLength()
	 */
	@Override
	public int getSentenceLength() {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see org.textplantform.common.provider.NetworkModelService#getModelFileStream()
	 */
	@Override
	public byte[] getModelFileStream() {
		// TODO Auto-generated method stub
		return modelByte;
	}

}
